<%-- 
    Document   : task
    Created on : Apr 28, 2013, 7:11:47 PM
    Author     : wan.fairul
--%>
<%@ include file="/WEB-INF/jsp/include/page_header.jspf" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>.: Personal Task :.</title> 
        <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/js/autoComplete/ui.autocomplete.css" />
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/autoComplete/jquery-1.2.6.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/autoComplete/ui.core.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/autoComplete/ui.autocomplete.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.blockUI.js"></script> 
        <script type="text/javascript">
            $(document).ready(function() {
                $("#user").autocomplete({
                    url: '${pageContext.request.contextPath}/personalTask?autocomplete',
                    minChars: 1,
                    max: 10,
                    width: 200,
                    scroll: false
                });
            });

            function clear(f) {
                $(f).clearForm();
            }

            function popupWin() {
                var url = '${pageContext.request.contextPath}/personalTask?viewDocuments';
                var left = (screen.width / 2) - (1000 / 2);
                var top = (screen.height / 2) - (1000 / 2);
                var params = 'width=1000';
                params += ', height=1000';
                params += ', top=' + top;
                params += ', left=' + left;
                //params += ', fullscreen=yes';
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes';
                params += ', status=no';
                params += ', toolbar=no';
                newwin = window.open(url, 'PopUp', params);
                if (window.focus) {
                    newwin.focus();
                }
                return false;
            }

            function unblockUI() {
                $.unblockUI();
            }

            function blockUI() {
                $.blockUI();
            }

            function validateFirst(form) {
                var validate = true;
                var message = "All field are required";
                if ($("#user").val() === '')
                    validate = false;
                if ($("#subject").val() === '')
                    validate = false;
                if ($("#msg").val() === '')
                    validate = false;
                if ($("#priorityCode").val() === '')
                    validate = false;
                if (validate === false)
                    alert(message);
                if (validate === true)
                {
                    document.getElementById("personalBtn").disabled = true; 
                    form.savePersonal.value = "The form is being submitted, please wait a moment...";
                    form.action = form.action + '?savePersonal';
                    form.submit();
                    return true;
                }
                return validate;
            }

            function isNumberKey(evt)
            {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode > 31 && (charCode < 45 || charCode > 57 || charCode == 47))
                    return false;

                return true;
            }

            function getPriorityDay(id) {
                var url = '${pageContext.request.contextPath}/personalTask?getPriorityDays&id=' + id;
                $.get(url,
                        function(data) {
                            $('#priority_day_count').val(data);
                        }, "html");
            }

        </script>
    </head>
    <body>
        <s:messages/>
        <s:errors/>
        <s:useActionBean beanclass="exatrez.stripes.util.ListUtil" var="list"/>
        <s:form beanclass="exatrez.stripes.action.PersonalAction" name="form1">   
            <div>
                <fieldset>
                    <div id="page-title">
                        <span class="title">New Personal Task</span>
                    </div>
                    <p>
                        <label>To :</label>
                        <s:text name="task.toUser" style="width:300px" id="user" class="clearAll"/>
                    </p>
                    <p>
                        <label>Subject :</label>
                        <s:textarea name="task.subject"  rows="5" cols="50" id="subject" class="clearAll"/>
                    </p>
                    <p>
                        <label>Message :</label>
                        <s:textarea name="msg"  rows="10" cols="50" id="msg" class="clearAll"/>
                    </p>
                    <p>
                        <label>Priority:</label>
                        <s:select name="priorityCode" style="width:150px" id="priorityCode" class="clearAll" onchange="getPriorityDay(this.value);">
                            <s:option value="">Please Choose</s:option>
                            <s:options-collection collection="${list.listPriorityCode}" label="priorityName" value="priorityCodeId"/>
                        </s:select>
                    </p>
                    <p>
                        <label>Priority Day:</label>
                        <s:text name="priorityDayCount" id="priority_day_count" onkeypress="return isNumberKey(event)" maxlength="3" class="clearAll"/>Day(s)
                    </p>  
                    <p>
                        <label>Upload :</label>
                        <s:button name="" value="Upload" class="btn" onclick="popupWin()"/>
                    </p>
                    <label>&nbsp;</label>
                    <s:submit name="savePersonal" value="Submit" id="personalBtn" class="btn" onclick="return validateFirst(this.form)"/>
                    <s:button name="clear" value="Clear" class="btn clear"/>
                    </p>
                </fieldset>
            </div>

        </s:form>
    </body>
</html>
